﻿Public Class FrmHouse

    Private x_tscd_old As X_TSCD
    Private x_nhacua_old As X_NhaCua

    Private x_tscd As X_TSCD
    Private x_nhacua As X_NhaCua

    Private _parentForm As SuperForm

    Public Sub New(ByVal x_tscd1 As X_TSCD, ByVal x_nhacua1 As X_NhaCua, ByVal parentForm As SuperForm)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.x_tscd_old = x_tscd1
        Me.x_nhacua_old = x_nhacua1

        Me.x_tscd = x_tscd1
        Me.x_nhacua = x_nhacua1

        Me._parentForm = parentForm

        ini()

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        x_tscd.setValue(I_TSCD.ColumnName_MaSO, CType(Me.txtMaSo.Text, String))
        x_tscd.setValue(I_TSCD.ColumnName_Ten, CType(Me.txtTen.Text, String))
        x_tscd.setValue(I_TSCD.ColumnName_DonViTrucThuoc, Me.txtDonVi.Text)
        x_tscd.setValue(I_TSCD.ColumnName_NguyenGia, Me.txtNguyenGia.Text)
        x_tscd.setValue(I_TSCD.ColumnName_TyLeHaoMon, Me.txtTLHaoMon.Text)
        x_tscd.setValue(I_TSCD.ColumnName_FAType, CONSTANT.FIXED_ASSETS_TYPE._HOUSE)
        x_tscd.setValue(I_TSCD.ColumnName_IsBusy, 0)
        x_tscd.save(True)

        x_nhacua.setValue(I_NhaCua.ColumnName_id, x_tscd.getValue(I_TSCD.ColumnName_id))
        x_nhacua.setValue(I_NhaCua.ColumnName_LoaiNha, Me.txtLoaiNha.Text)
        x_nhacua.setValue(I_NhaCua.ColumnName_DienTich, Me.txtDienTich.Text)
        x_nhacua.setValue(I_NhaCua.ColumnName_MucDichSuDung, Me.txtMucDichSd.Text)
        x_nhacua.setValue(I_NhaCua.ColumnName_NgayXayDung, Me.dtpNgayXD.Text)
        x_nhacua.save(True)


        Me._parentForm.loadFA()
        Me._parentForm.loadDetail()
        Me._parentForm.specifyCorrespondingDetail()

        Me.Close()

    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ini()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Function ini() As Boolean
        Me.txtMaSo.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_MaSO)
        Me.txtTen.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_Ten)
        Me.txtLoaiNha.Text = Me.x_nhacua_old.getValue(I_NhaCua.ColumnName_LoaiNha)
        Me.txtDienTich.Text = Me.x_nhacua_old.getValue(I_NhaCua.ColumnName_DienTich)
        Me.dtpNgayXD.Text = Me.x_nhacua_old.getValue(I_NhaCua.ColumnName_NgayXayDung)
        Me.txtMucDichSd.Text = Me.x_nhacua_old.getValue(I_NhaCua.ColumnName_MucDichSuDung)
        Me.txtNguyenGia.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_NguyenGia)
        Me.txtTLHaoMon.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_TyLeHaoMon)
        Me.txtDonVi.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_DonViTrucThuoc)
        Return True
    End Function
End Class